package com.example.index.service.impl;

import com.example.index.entity.JobImage;
import com.example.index.dao.JobImageDao;
import com.example.index.service.JobImageService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 就业服务的图片
(JobImage)表服务实现类
 *
 * @author makejava
 * @since 2023-08-29 16:45:51
 */
@Service("jobImageService")
public class JobImageServiceImpl implements JobImageService {
    @Resource
    private JobImageDao jobImageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JobImage queryById(Integer id) {
        return this.jobImageDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param jobImage 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<JobImage> queryByPage(JobImage jobImage, PageRequest pageRequest) {
        long total = this.jobImageDao.count(jobImage);
        return new PageImpl<>(this.jobImageDao.queryAllByLimit(jobImage, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param jobImage 实例对象
     * @return 实例对象
     */
    @Override
    public JobImage insert(JobImage jobImage) {
        this.jobImageDao.insert(jobImage);
        return jobImage;
    }

    /**
     * 修改数据
     *
     * @param jobImage 实例对象
     * @return 实例对象
     */
    @Override
    public JobImage update(JobImage jobImage) {
        this.jobImageDao.update(jobImage);
        return this.queryById(jobImage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.jobImageDao.deleteById(id) > 0;
    }
}
